package datetime

import (
	"strconv"
	"time"
)

//时区
type TimeZone interface {
	Name() string
	Offset() int64
}

type timezone struct {
	offset int64
}

func (tz timezone) Name() string {
	z := tz.offset / 3600
	if z > 0 {
		return "E" + strconv.Itoa(int(z))
	} else if z < 0 {
		return "W" + strconv.Itoa(int(z))
	} else {
		return "ZERO"
	}
}

func (tz timezone) Offset() int64 {
	return tz.offset
}

type zones struct {
	E12   timezone
	E11   timezone
	E10   timezone
	E9    timezone
	E8    timezone
	E7    timezone
	E6    timezone
	E5    timezone
	E4    timezone
	E3    timezone
	E2    timezone
	E1    timezone
	ZERO  timezone
	W1    timezone
	W2    timezone
	W3    timezone
	W4    timezone
	W5    timezone
	W6    timezone
	W7    timezone
	W8    timezone
	W9    timezone
	W10   timezone
	W11   timezone
	W12   timezone
	LOCAL timezone
}

func getTimeZoneName(offset int64) (name string) {
	z := offset / 3600
	if z > 0 {
		name = "E" + strconv.Itoa(int(z)) //fmt.Sprint("E", z)
	} else if z < 0 {
		name = "W" + strconv.Itoa(int(z)) //fmt.Sprint("W", -z)
	} else {
		name = "ZERO"
	}
	return
}

var Zones zones

func init() {
	Zones.E12.offset = 3600 * 12
	Zones.E11.offset = 3600 * 11
	Zones.E10.offset = 3600 * 10
	Zones.E9.offset = 3600 * 9
	Zones.E8.offset = 3600 * 8
	Zones.E7.offset = 3600 * 7
	Zones.E6.offset = 3600 * 6
	Zones.E5.offset = 3600 * 5
	Zones.E4.offset = 3600 * 4
	Zones.E3.offset = 3600 * 3
	Zones.E2.offset = 3600 * 2
	Zones.E1.offset = 3600 * 1
	Zones.ZERO.offset = 3600 * 0
	Zones.W1.offset = 3600 * -1
	Zones.W2.offset = 3600 * -2
	Zones.W3.offset = 3600 * -3
	Zones.W4.offset = 3600 * -4
	Zones.W5.offset = 3600 * -5
	Zones.W6.offset = 3600 * -6
	Zones.W7.offset = 3600 * -7
	Zones.W8.offset = 3600 * -8
	Zones.W9.offset = 3600 * -9
	Zones.W10.offset = 3600 * -10
	Zones.W11.offset = 3600 * -11
	Zones.W12.offset = 3600 * -12
	_, offset := time.Now().Zone()
	Zones.LOCAL.offset = int64(offset)
}
